<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
attr.ctrlName = '<?php echo $ctrlName; ?>';
attr.game_gift = <?php echo $game_gift ?>;
attr.reservation_type = <?php echo $reservation_type ?>;
attr.card_type = <?php echo $card_type ?>;
attr.gift_status = <?php echo $gift_status ?>;


/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.GridPanel({
    url: list.baseUrl + attr.ctrlName+'/getCustomerList',
    tbar:[{
        text:'导出过滤顾客',
        cls:'btn-show',
        hidden:!Ext.permission[attr.ctrlName + '/exportCustomerList'.toLowerCase()],
        handler:function() {
            var sortInfo = list.grid.store.getSortState();
            if(sortInfo) {
                list.grid.store.baseParams['sort'] = sortInfo['field'];
                list.grid.store.baseParams['dir'] = sortInfo['direction'];
            }
            location.href = list.baseUrl + attr.ctrlName + '/exportCustomerList?'+ Ext.urlEncode(list.grid.store.baseParams);
        }
    },'-',{
        text:'导入流量充值记录',
        cls:'btn-show',
        handler:function() {
            var win = new ZM.PopUp({
                title:'导入流量充值记录',
                type:'s',
                items:{
                    xtype:'formpanel',
                    url:list.baseUrl+ attr.ctrlName+'/importList',
                    fileUpload:true,
                    success:function(res) {
                        ZM.bo.msg('success',res.detail);
                        list.grid.store.reload();
                        win.close();
                    },
                    items:[{
                        xtype:'hidden',
                        name:'type',
                        value:3
                    },{
                        inputType:'file',
                        fieldLabel:'流量充值记录(excel)',
                        name:'file',
                        allowBlank:false
                    }]
                }
            }).show();
        }
    }],
    columns:[
        {header:'ID',dataIndex:'customer_id',filter:{}},
        {header:'奖品',dataIndex:'gift_type',sort:true,filter:{xtype:'combofield',options:[['','全部'],['0','无'],['-1','已中奖']].concat(attr.game_gift)}
            ,renderer:function(val) {
            return ZM.id2name(val,attr.game_gift);
        }},
        {header:'奖品状态',dataIndex:'gift_status',filter:{xtype:'combofield',options:[['','全部']].concat(attr.gift_status)},renderer:function(val,m,r) {
            if(r.json.gift_type == 0) {
                return '';
            }
            return ZM.id2name(val,attr.gift_status);
        }},
        {header:'openid',dataIndex:'openid',width:200,filter:{}},
        {header:'抽奖次数',dataIndex:'lottery_times',sort:true},
        {header:'创建时间',dataIndex:'customer_time_create',width:140,filter:{xtype:'daterangefield'}},
        {header:'获奖时间',dataIndex:'customer_time_lottery',width:140,filter:{xtype:'daterangefield'}},
        {header:'姓名',dataIndex:'customer_name',filter:{}},
        {header:'手机',dataIndex:'customer_phone',filter:{}},
        {header:'卡券类型',dataIndex:'card_type',filter:{xtype:'combofield',options:[['','全部'],['0','未领取'],['-1','已领取']].concat(attr.card_type)},renderer:function(val,m,r) {
            var html = [];
            Ext.each(r.json.card_list,function(item,i) {
                html.push(ZM.id2name(item.card_type,attr.card_type));
            });
            return html.join('<br/>');
        }},
        {header:'卡券号',dataIndex:'card_number',width:140,renderer:function(val,m,r) {
            var html = [];
            Ext.each(r.json.card_list,function(item,i) {
                html.push(item.card_number);
            });
            return html.join('<br/>');
        }},
        {header:'卡券时间',dataIndex:'card_time_create',width:140,filter:{xtype:'daterangefield'},renderer:function(val,m,r) {
            var html = [];
            Ext.each(r.json.card_list,function(item,i) {
                html.push(item.card_time_create);
            });
            return html.join('<br/>');
        }},
        {header:'预约店面',dataIndex:'user_name'},
        {header:'预约店面编码',dataIndex:'user_code'},
        {header:'预约类型',dataIndex:'customer_reservation_type',filter:{xtype:'combofield',options:[['','全部'],['0','未预约']].concat(attr.reservation_type)},renderer:function(val) {
            return ZM.id2name(val,attr.reservation_type);
        }},
        {header:'状态',dataIndex:'customer_status',width:65,renderer:function(val) {
           return ZM.status(val == -2 ? '0' : 1);
        },filter:{
            xtype:'combofield',
            options:[['','全部'],['-2','禁用'],['0','激活']]
        }},
        {header:'操作',renderer:function(v,p,r){
            var str = '';
            //str += Ext.rd('查看抽奖历史','fireDetail',r,attr.ctrlName+'/getLotteryHistoryList');
            if(r.json.customer_status == -2) {
                str += Ext.rd('激活','fireEnable',r,attr.ctrlName+'/enableCustomer');
            } else {
                str += Ext.rd('禁用','fireDisable',r,attr.ctrlName+'/disableCustomer');
            }
            return str;
        }}
    ]
});
/*
| -------------------------------------------------------------------
|  List Grid Action
| -------------------------------------------------------------------
*/
list.grid.fireDisable = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确认?','确定要禁用顾客['+r.nickname+']?',function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/disableCustomer',
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

list.grid.fireEnable = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确认?','确定要激活顾客['+r.nickname+']?',function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/enableCustomer',
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include dirname(__FILE__).'/common/footer.php'; ?>